package com.neutech.gui;

import com.neutech.constant.Constant;
import com.neutech.util.ImageUtil;

import java.awt.*;

public class PlanetaryMovement extends MyFrame {
    public PlanetaryMovement(String string) throws HeadlessException {
        super(string);
    }



    public int earth_x = Constant.CONSTANT_WIDTH/2 - Constant.CONSTANT_EARTH_WIDTH/2 + Constant.LONG_AXIS;
    public int earth_y = Constant.CONSTANT_HEIGHT/2 - Constant.CONSTANT_EARTH_HEIGHT/2;
    public double theta;//这个一定要是小数才行呐
    public Image backgroundImage = ImageUtil.getImage("com/neutech/resource/sky01.jpg");
    public Image sun = ImageUtil.getImage("com/neutech/resource/01sun.png");
    public Image earth = ImageUtil.getImage("com/neutech/resource/04earth.png");
    @Override
    public void paint(Graphics g) {
        //画背景图
        g.drawImage(backgroundImage, Constant.CONSTANT_BACKGROUND_X, Constant.CONSTANT_BACKGROUND_Y,
                Constant.CONSTANT_WIDTH, Constant.CONSTANT_HEIGHT, null);
        //画太阳
        g.drawImage(sun,Constant.CONSTANT_WIDTH/2 - Constant.CONSTANT_SUN_WIDTH/2,
                Constant.CONSTANT_HEIGHT/2 - Constant.CONSTANT_SUN_HEIGHT/2,
                Constant.CONSTANT_SUN_WIDTH, Constant.CONSTANT_SUN_HEIGHT, null);
        //画地球
        g.drawImage(earth, earth_x,earth_y, Constant.CONSTANT_EARTH_WIDTH,
                Constant.CONSTANT_EARTH_HEIGHT, null);


        //地球运动轨迹
        earth_x = (int)(Constant.LONG_AXIS * Math.cos(theta)) + Constant.CONSTANT_WIDTH /2;
        earth_y = (int)(Constant.SHORT_AXIS * Math.sin(theta)) + Constant.CONSTANT_HEIGHT/2;
        theta += Constant.SPEED;
    }
}
